package com.android.openapp.ui;

import android.util.Log;

import com.android.openapp.services.Controller;
import com.socrata.api.RequestException;
import com.socrata.data.View;

import data.Place;
/**
 * 
 * @author Allieri Tommaso
 * Thread di download dei metadati
 *
 */
public class Metainit extends Thread{
	
	public static int flag=0; //flag di download
	public static int worked=0; //flag worked***********
	
	Integer index;
	public Metainit(Integer index) {
		this.index=index;
	}
	
	@Override
	public void run() {
		
		
			Log.i("test ","thread download");
			download();
			
				
			
		
		super.run();
	}
	synchronized void download(){
		View v=new View();
		View temp=new View();
		try {
			synchronized (Place.listmetadati) {
				
				Log.d("Download function",this.getName()+ " "+ Integer.toString(index));
				temp=v.get(Place.datasetM[index].toLowerCase(), Controller.c, View.class);
				//Log.d("api_id",temp.getColumnById(9897690).getName());
				Log.d("Download function",this.getName()+ "pippo "+ temp.getDescription());
				Place.listmetadati.set(index, temp);
				flag++;
				worked++;
				
			}
			
		} catch (RequestException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
			worked++;
			Log.e("download method","error to download");
		}
		
		Log.i(this.getName(),"metadati "+Integer.toString(index)+" scaricato");
	}
}